﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.Products;

@model ManufacturerListModel

@*<div class="row">

        <div class="col-md-12">

            <div class="input-group mb5">
                <input type="text" id="txt_SearchStr" class="form-control" placeholder="供应商关键字...">
                <span class="input-group-btn">
                    <button id="btn_query" type="button" class="btn btn-primary" style="border:1px solid #dddddd;"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                </span>
            </div>

            <table class="table table-striped table-hover" id="datatable">
                <thead>
                    <tr>
                        <th class="bs-checkbox " style="text-align: center; vertical-align: middle; width: 36px; " data-field="id"><div class="th-inner "><input name="btSelectAll" type="checkbox"></div></th>
                        <th data-field="Name"><div class="th-inner">供应商名称</div></th>
                        <th data-field="DisplayOrder" class="text-center"><div class="th-inner">排序</div></th>
                        <th data-field="Status" data-align="center" class="text-center"><div class="th-inner">状态</div></th>
                        <th data-field="Operator" data-align="center" class="text-right"><div class="th-inner">操作</div></th>
                    </tr>
                </thead>
                <tbody>
                    @{
                        int index = 0;
                        foreach (var manufacturer in Model.Items)
                        {
                            <tr>
                                <td class="bs-checkbox ">
                                    <input data-index="@index" name="btSelectItem" class="btSelectItem" type="checkbox" value="@manufacturer.Id">
                                </td>
                                <td>@manufacturer.Name</td>
                                <td class="text-center">@manufacturer.DisplayOrder</td>
                                <td class="text-center">
                                    <div class="switch switch-primary">
                                        <input id="StatusRadioSwitch_@manufacturer.Id" type="radio" name="StatusRadioSwitch_@manufacturer.Id" checked="@manufacturer.Status">
                                        <label for="StatusRadioSwitch_@manufacturer.Id" class="mbn"/>
                                    </div>
                                </td>
                                <td class="text-right">
                                    <a class="btn btn-sm btn-primary btn_addselect_Supplier" data-id="@manufacturer.Id" data-name="@manufacturer.Name" href="javascript:;" title="选择"><i class="glyphicon glyphicon-pencil mr5"></i> 选择</a>
                                </td>

                            </tr>
                            index++;
                        }

                    }
                </tbody>
            </table>
        @{
                            var pager = Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber");
                        }

                        @if (!pager.IsEmpty())
                        {
                            <div class="fixed-table-pagination" style="display: block;">
                                @Html.Raw(pager.ToString())
                            </div>
                        }
        </div>
    </div>*@


<div class="row">
    <div class="col-md-12">
        <div class="input-group mb5">
            <input type="text" id="txt_SearchManufacturerStr" class="form-control" placeholder="供应商关键字..." onkeydown="if(event.keyCode==13){event.keyCode=0;event.returnValue=false;}">
            <span class="input-group-btn">
                <button id="btn_PopManufacturerQuery" type="button" class="btn btn-primary" style="border:1px solid #dddddd;"><span class="glyphicon glyphicon-search"></span> 搜索</button>
            </span>
        </div>
        <table class="table table-striped table-hover" id="manufacturer_datatable"></table>
    </div>
</div>

<script type="text/javascript">


	$(function () {

		//供应商列表
		$("#manufacturer_datatable").bootstrapTable({
			url: "/Manufacturer/AsyncList",
			method: 'get',
			striped: true,
			cache: false,
			pagination: true,
			queryParams: function (params) {
				var temp =
					{
						key: $("#txt_SearchManufacturerStr").val(),
						pageSize: params.limit,
						pageIndex: (params.offset / params.limit)
					};
				return temp;
			},
			sidePagination: "server",
			idField: 'Id',
			pageNumber: 1,
			pageSize: 10,
			search: false,
			strictSearch: true,
			showRefresh: false,
			clickToSelect: false,
			uniqueId: "Id",
			showToggle: false,
			cardView: false,
			detailView: false,
			columns: [
				{ checkbox: true },
				{ field: 'id', visible: false },
				{ field: 'Name', title: '供应商名称', align: 'left' },
				{ field: 'DisplayOrder', title: '排序' },
				{
					field: 'Status', title: '状态', formatter: function (value, row, index) {
						if (value == true) {
							return "启用";
						}
						if (value == false) {
							return "禁用";
						}
					}
				},
				{
					field: 'operate', title: '操作', align: 'center', width: '100',
					events: operateEventsPopManufacturer,
					formatter: function (value, row, index) {
						return [
							'<button type="button" class="btn btn-sm btn-info rowSelect" data-id="@Model.RowIndex" data-target="@Model.Target"><i class="fa fa-pencil-square-o"></i>&nbsp;选择</button>'
						].join('');
					}
				}
			],
			onPageChange: function (number, size) {
				m_pagerow = (number - 1) * size;
			},
			onLoadSuccess: function (data) {
				//console.log('load');
			},
			onLoadError: function (a, b) {  //加载失败时执行
				console.log('加载数据失败');
			}
		});

		//查询
		$("#btn_PopManufacturerQuery").on('click', function () {
			var keys = $("#btn_PopManufacturerQuery").val();
			$("#manufacturer_datatable").bootstrapTable('refresh');
		});



	});
</script>